package com.chunlei.complete.client;

import cn.hutool.core.thread.ThreadUtil;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;

public class ThreadTest {
    public static void main(String[] args) {
        LinkedBlockingQueue<Future> queue = new LinkedBlockingQueue<>();
        for (int i = 0; i < 10000; i++) {
            int finalI = i;
            Future<Integer> future = ThreadUtil.execAsync(() -> finalI);
            queue.add(future);
        }

        for (Future future : queue) {
            ThreadUtil.execAsync(() -> {
                try {
                    System.out.println(future.get());
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } catch (ExecutionException e) {
                    throw new RuntimeException(e);
                }
            });
        }
    }
}
